/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-01-18
 * Time: 22:42
 */
public class test2 {
    /*
    LeetCode 3 无重复字符的最大字串   滑动窗口
     */
    public int lengthOfLongestSubstring(String ss) {
        // 转换为字符数组
        char[] s = ss.toCharArray();
        // 哈希数组记录重复数字
        int[] hash = new int[128];
        int left = 0;
        int right = 0;
        int n = ss.length();
        int ret = 0;
        while(right<n){
            hash[s[right]]++;
            while(hash[s[right]]>1){
                hash[s[left]]--;
                left++;
            }
            ret = Math.max(ret,right-left+1);
            right++;
        }
        return ret;
    }
}
